﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Vds2465Telegrams;

namespace Vds2465Parser
{
	internal static class GenParse_History
	{
		#region private constants

		private const byte SentByte = 0x10;
		private const byte RedirectionByte = 0x20;
		private const byte SentFailureByte = 0x40;
		private const byte OperationPanelSwitchOffRedirectionByte = 0x80;
		
		#endregion private constants

		#region internal methods

		internal static byte GenerateByte(eHistory history)
		{
			byte historyByte = 0x0;

			switch (history)
			{
				case eHistory.SentFailure:
					historyByte = SentFailureByte;
					break;
				case eHistory.Redirection:
					historyByte = RedirectionByte;
					break;
				case eHistory.Sent:
					historyByte = SentByte;
					break;
				case eHistory.OperationPanelSwitchOffRedirection:
					historyByte = OperationPanelSwitchOffRedirectionByte;
					break;
				default:
					// TODO handle error (unknown value for eHistory)
					break;
			}

			return historyByte;
		}

		internal static bool ParseByte(byte historyByte, out eHistory history)
		{
			// set default value
			bool bRetVal = true;
			history = eHistory.Sent;
			
			switch (historyByte)
			{
				case SentByte:
					history = eHistory.Sent;
					break;
				case RedirectionByte:
					history = eHistory.Redirection;
					break;
				case SentFailureByte:
					history = eHistory.SentFailure;
					break;
				case OperationPanelSwitchOffRedirectionByte:
					history = eHistory.OperationPanelSwitchOffRedirection;
					break;
								
				default:
					// TODO handle error (unknown value for errorCodeByte)
					bRetVal = false;
					break;
			}

			return bRetVal;
		}

		#endregion internal methods
	}
}
